package day1211_2;

import day1206_2.Shop;

class SellWindow  implements  Runnable{
    Object o;
    SellWindow(Object ob){
        o=ob;
    }

    int ticket=10;//火车站中有10张票
    void sell(){
        synchronized(o) {
            if(ticket==0){System.exit(0);}
            Thread.yield();
            System.out.println("目前剩余的票的数量是：" + --ticket);
        }
    }



    public void run() {
        while(true){
            sell();
        }
    }
}



public class T1 {
    public static void main(String[] args) {

        Shop  s=new Shop();//锁

        SellWindow  window=new SellWindow(s);
        Thread  person1=new Thread(window);
        Thread  person2=new Thread(window);
        person1.start();
        person2.start();
    }
}










